package com.huanf.impl;

import com.huanf.service.AsyncService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;

/**
 * @author: 35238
 * 功能: 异步调用
 * 时间: 2023-12-30 12:46
 */
@DubboService
@Service
public class AsyncServiceImpl implements AsyncService {
    @Override
    //CompletableFuture是专门用于异步调用的类
    public CompletableFuture<String> sayHello(String name) {
        return CompletableFuture.supplyAsync(() -> {
            System.out.println("我是provider模块，我实现了api模块的AsyncService的sayHello方法，你好: "+name);
            try {
                //等待3秒
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "api模块的AsyController的Lambda表达式的value值，拿到的就是当前这串字符串";
        });
    }
}